package cn.sccl.mybatis.dao;

import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import cn.sccl.mybatis.pojo.User;

/**
 * @author 饶爽
 * @time 2019年9月15日 下午10:34:56
 * @version 1.0.0
 * User数据库访问实现类
*/
public class UserDaoImpl implements UserDao {
    
    //注入
    private SqlSessionFactory sqlSessionFactory;
    public UserDaoImpl(SqlSessionFactory sessionFactory) {
        this.sqlSessionFactory = sessionFactory;
    }
    @Override
    public User selectUserById(Integer id) {
        SqlSession session = sqlSessionFactory.openSession();
        return session.selectOne("test.findUserById", id);
    }
    @Override
    public List<User> queryUserByUsername(String username) {
        SqlSession session = sqlSessionFactory.openSession();
        return session.selectList("test.findUserByUsername", username);
    }
    @Override
    public void saveUser(User user) {
        SqlSession session = sqlSessionFactory.openSession();
        session.insert("test.insertUser", user);
        session.commit();
    }

}
